View Javadoc

1   // Heap2HeapReference.java, created Tue Feb 27  2:59:43 2001 by joewhaley
2   // Copyright (C) 2001-3 John Whaley <jwhaley@alum.mit.edu>
3   // Licensed under the terms of the GNU LGPL; see COPYING for details.
4   package joeq.Assembler;
5   
6   import java.io.DataOutput;
7   import java.io.IOException;
8   import joeq.Class.PrimordialClassLoader;
9   import joeq.Class.jq_Class;
10  import joeq.Memory.HeapAddress;
11  
12  /***
13   * Heap2HeapReference
14   *
15   * @author  John Whaley <jwhaley@alum.mit.edu>
16   * @version $Id: Heap2HeapReference.java 1941 2004-09-30 03:37:06Z joewhaley $
17   */
18  public class Heap2HeapReference extends Reloc {
19  
20      private HeapAddress from_heaploc;
21      private HeapAddress to_heaploc;
22      
23      /*** Creates new Heap2HeapReference */
24      public Heap2HeapReference(HeapAddress from_heaploc, HeapAddress to_heaploc) {
25          this.from_heaploc = from_heaploc; this.to_heaploc = to_heaploc;
26      }
27  
28      public HeapAddress getFrom() { return from_heaploc; }
29      public HeapAddress getTo() { return to_heaploc; }
30      
31      public void patch() {
32          from_heaploc.poke(to_heaploc);
33      }
34      
35      public void dumpCOFF(DataOutput out) throws IOException {
36          out.writeInt(from_heaploc.to32BitValue()); // r_vaddr
37          out.writeInt(1);                           // r_symndx
38          out.writeChar(Reloc.RELOC_ADDR32);         // r_type
39      }
40      
41      public String toString() {
42          return "from heap:"+from_heaploc.stringRep()+" to heap:"+to_heaploc.stringRep();
43      }
44      
45  
46      public boolean equals(Heap2HeapReference that) {
47          if (this.from_heaploc.difference(that.from_heaploc) != 0)
48              return false;
49          return true;
50      }
51      
52      public boolean equals(Object obj) {
53          if (obj instanceof Heap2HeapReference) {
54              return equals((Heap2HeapReference) obj);
55          }
56          return false;
57      }
58      
59      public int hashCode() {
60          // Note: hash code changes depending on address relocation!
61          int v1 = from_heaploc.to32BitValue();
62          return v1;
63      }
64      
65      public static final jq_Class _class = (jq_Class) PrimordialClassLoader.loader.getOrCreateBSType("Ljoeq/Assembler/Heap2HeapReference;");
66  }